package com.company.clientscard.main.widgets.clientform;

import com.company.clientscard.main.widgets.general.TableManager;
import com.company.clientscard.shared.proxy.DocumentProxy;
import com.company.clientscard.shared.proxyManager.DocumentProxyManager;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;

public class ClientsForm extends FlexTable {
	final Label clientName = new Label("Client login: admin@dobro.com.ua");

	final DatePick hp1 = new DatePick();
	final Button printButton = new Button("Show in PDF");
	final Button exportToXLSButton = new Button("Export to xls");

	final DocumentTable docTable;
	final TableManager<DocumentProxy> docTableManager;
	DocumentProxyManager docProxyManager = new DocumentProxyManager();

	public ClientsForm() {
		docTableManager = new TableManager<DocumentProxy>(docProxyManager);
		docTable = new DocumentTable(docTableManager);

		printButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				Window.open("http://" + Window.Location.getHost()
						+ "/reportsServlet/report?reportFilename=Sales",
						"_blank", null);
			}
		});

		exportToXLSButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				Window.open(
						"http://"
								+ Window.Location.getHost()
								+ "/reportsServlet/report?reportFilename=Sales&reportFormat=XLS_EXPORT"
								+ "&reportDate1=" + hp1.getDate1()
								+ "&reportDate2=" + hp1.getDate2(), "_blank",
						null);
			}
		});

		hp1.add(printButton);
		hp1.add(exportToXLSButton);
		hp1.setVerticalAlignment(HorizontalPanel.ALIGN_MIDDLE);

		setWidth("100%");
		setWidget(0, 0, clientName);
		setWidget(1, 0, hp1);
		setWidget(2, 0, docTable);

		getCellFormatter().setHorizontalAlignment(0, 0,
				HasHorizontalAlignment.ALIGN_CENTER);
	}
}
